package com.zhiwu.uhf.util;

import android.app.Dialog;
import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.zhiwu.uhf.R;

import androidx.annotation.NonNull;

public class CustomDialog extends Dialog {
    //自定义dialog
    private Context mContext;
    private Button btnSure;
    private Button btnCancle;
    private TextView title;
    private TextView message;

    public CustomDialog(@NonNull Context context) {
        super(context, R.style.CustomDialog);
        this.mContext = context;
        initView();
    }

    public void setMessage(String infoM) {
        if (!TextUtils.isEmpty(infoM)) {
            message.setText(infoM);
        }
    }

    public void setTitle(String infoT) {
        if (!TextUtils.isEmpty(infoT)) {
            title.setText(infoT);
        }
    }

    public void setBtnS(String btnS) {
        if (!TextUtils.isEmpty(btnS)) {
            btnSure.setText(btnS);
        }
    }

    public void setBtnC(String btnC) {
        if (!TextUtils.isEmpty(btnC)) {
            btnCancle.setText(btnC);
        }
    }

    public void initView() {
        View view = LayoutInflater.from(mContext).inflate(R.layout._dialog, null);
        title = view.findViewById(R.id.title);
        message = view.findViewById(R.id.message);
        btnSure = view.findViewById(R.id.dialog_confirm_sure);
        btnCancle = view.findViewById(R.id.dialog_confirm_cancle);
        setContentView(view);
    }

    //确定键监听器
    public void setOnSureListener(View.OnClickListener listener) {
        btnSure.setOnClickListener(listener);
    }

    //取消键监听器
    public void setOnCanlceListener(View.OnClickListener listener) {
        btnCancle.setOnClickListener(listener);
    }

}
